home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Presentations / STL & Modern C++ / STL10.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  409 b   |  19 lines  |  [TEXT/CWIE]

  1. // STL10.cp
  2. #include <string>
  3.  
  4. int main()
  5. {
  6.     std::string    a = "shared string";
  7.     std::string    b(a);            // a and b are sharing the same string buffer
  8.  
  9.     if (a[0] != b[0])                    // line 1
  10.     {
  11.         a = b = "un" + a;                // line 2
  12.     }
  13.     if (a.c_str()[0] == b.c_str()[0])    // line 3
  14.     {
  15.         a = b = "un" + a;                // line 4
  16.     }
  17.     // a and b are no longer sharing the same string buffer
  18.     // Question: At what line is the buffer copied?
  19. }